import logging

from libs.auth import check_post_request
from libs.common import success
from libs.form import RawJsonForm
from trade.models.order import Orders

logger = logging.getLogger(__name__)


def my_order_list(request):
    return_code, return_content = check_post_request(request)
    if return_code != 0:
        return return_content
    member_id = return_content
    form = RawJsonForm(request.body)
    p = form.get_page()
    order_list = Orders.objects.filter(member_id=member_id).order_by("-updated").all()[p.start:p.end].values()
    rd = {
        'data': list(order_list),
        'page': p.page,
        'size': p.size
    }
    return success(**rd)
